// 退出
$('#quit').on('click',function(){
    layer.confirm('您确定退出吗？', {
        btn: ['确定','取消'] //按钮
      }, function(){
        layer.msg('退出成功', {icon: 1});
        location.href="login.html"
        localStorage.removeItem('token')
      });
      
})

// 渲染页面
function show(){
    $.ajax({
        url:'/my/userinfo',
        success:function(res){

            if(res.status===0){
                let names = res.data.nickname || res.data.username
                $('#username').text(names)
                
            //  判断是否有照片
                if(res.data.user_pic){
                    $('.layui-nav-img').attr('src', res.data.user_pic).show();
                }
                else {
                    // console.log(res.data.username.substring(0,1).toUpperCase())
                    let user = names.substring(0,1).toUpperCase()
                    $('.user').text(user).css({
                        display:'inline-block'
                    })
                }
            }
           else if(res.status===1){
                localStorage.removeItem('token')
                location.href="/login.html"
           }
            
        }
    })
}
show()